//
//  LXBaseRequester.h
//  ProjectSource_Demo
//
//  Created by Liu on 16/3/28.
//  Copyright © 2016年 AngryBear. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, LXHTTPRequestMethod) {
    LXHTTPRequestMethodGet,     //GET
    LXHTTPRequestMethodPost,    //POST
    LXHTTPRequestMethodHead,    //HEAD
    LXHTTPRequestMethodPut,         //PUT
    LXHTTPRequestMethodDelete,      //DELETE
    LXHTTPRequestMethodPatch        //PATCH
};

@class LXBaseRequest;
typedef void (^NetworkSuccessHandle)(LXBaseRequest *request, id response);
typedef void (^NetworkFailureHandle)(LXBaseRequest *request);

@interface LXBaseRequest : NSObject

@property (nonatomic, strong) NSOperation *operation;

/** 请求的url字符串 */
- (NSString *)urlString;

/** 请求的超时时间，default is 15 seconds. */
- (NSTimeInterval)timeoutInterval;

/** 请求的缓存策略 */
- (NSURLRequestCachePolicy)cachePolicy;

/** http请求的方法 */
- (LXHTTPRequestMethod)method;

/** 请求头 */
- (NSDictionary *)httpHeader;

/** 请求参数,子类不重载的话，将转化子类的属性，生成包含子类属性的字典 */
- (NSDictionary *)requestParameters;

/** 请求的get字符串, 按升序排列 */
- (NSString *)parametersString;


- (void)startWithCompletionBlockWithSuccess:(NetworkSuccessHandle)success
                                    failure:(NetworkFailureHandle)failure;
- (void)cancelRequest;

- (NetworkSuccessHandle)successHandle;
- (NetworkFailureHandle)failureHandle;

@end
